// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "ModularAIController.h"
#include "Teams/LyraTeamAgentInterface.h"

#include "LyraPlayerBotController.generated.h"

namespace ETeamAttitude { enum Type : int; }
struct FGenericTeamId;

class APlayerState;
class UAIPerceptionComponent;
class UObject;
struct FFrame;

/**
 * ALyraPlayerBotController
 *
 *	该项目中玩家机器人使用的控制器类。
 */
UCLASS(Blueprintable)
class ALyraPlayerBotController : public AModularAIController, public ILyraTeamAgentInterface
{
	GENERATED_BODY()

public:
	ALyraPlayerBotController(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

	//~ILyraTeamAgentInterface接口
	virtual void SetGenericTeamId(const FGenericTeamId& NewTeamID) override;
	virtual FGenericTeamId GetGenericTeamId() const override;
	virtual FOnLyraTeamIndexChangedDelegate* GetOnTeamIndexChangedDelegate() override;
	ETeamAttitude::Type GetTeamAttitudeTowards(const AActor& Other) const override;
	//~End of ILyraTeamAgentInterface接口

	// 尝试重启此控制器（例如，重新生成）
	void ServerRestartController();

	// 更新AI的队伍态度
	UFUNCTION(BlueprintCallable, Category = "Lyra AI Player Controller")
	void UpdateTeamAttitude(UAIPerceptionComponent* AIPerception);

	virtual void OnUnPossess() override; // 取消控制时调用

private:
	UFUNCTION()
	void OnPlayerStateChangedTeam(UObject* TeamAgent, int32 OldTeam, int32 NewTeam); // 玩家状态队伍改变回调

protected:
	// 当玩家状态被设置或清除时调用
	virtual void OnPlayerStateChanged(); // 玩家状态改变回调

private:
	void BroadcastOnPlayerStateChanged(); // 广播玩家状态改变

protected:	
	//~AController接口
	virtual void InitPlayerState() override; // 初始化玩家状态
	virtual void CleanupPlayerState() override; // 清理玩家状态
	virtual void OnRep_PlayerState() override; // 玩家状态复制回调
	//~End of AController接口

private:
	UPROPERTY()
	FOnLyraTeamIndexChangedDelegate OnTeamChangedDelegate; // 队伍改变委托

	UPROPERTY()
	TObjectPtr<APlayerState> LastSeenPlayerState; // 最后看到的玩家状态
};